<form method="post" id="post-checkout" class="store-form" action="<?php echo $this->baseurl("/appstore/completeCheckout") ?>">
<div class="grid_16">
    <h2 class="smart"><?php echo $this->__('Shopping Cart');?></h2>
    <?php App::Component('appStore')->Helper('Data')->renderShoppingCart();?>
</div>	
<div class="clear gap "></div>
<div class="grid_10">
<?php if(App::Config()->Setting('enablediscountmodule','Yes') == 'Yes'):?>
	<h3><?php echo $this->__("Discount");?></h3>
	<div id="discount-area">
		<?php $discount =  App::Component('appStore')->Helper('Checkout')->calculateDiscount();?>
		<?php if($discount > 0):?>
			<strong style ="color:green"> Your coupon reedeem amount is <?php echo App::Config()->setting('currency','USD') . $discount ;?>  </strong>
		<?php else:?>
		<ul>
			<li><?php echo $this->__("Reedeem your Gift certificate.");?></li>
			<li>
			<label>Copun Code</label>
			<span><input type="text" name="discount[code]" id="verify_discount_code" class="input"></span>
			<label>&nbsp;<input type="button" name="discount[verify]" id="verify_discount_coupon" class="button orange small" value="Submit" /></label>
			</li>
		</ul>
		<?php endif;?>
	</div>
	
	<script type="text/javascript">

		var _obj = jQuery('#verify_discount_code');
		
		jQuery(document).ready(function () {
			jQuery("#verify_discount_coupon").click(function(event) {	
				var code = jQuery(_obj ).val();	
						
				jQuery('.inlineerror').remove();
				if(code != ''){
					jQuery.getJSON(siteInfo.baseUrl + '/appstore/submitdiscountcode/' + code, function(data) {
						if(data.response == 'Success'){
							jQuery('#discount-area').html('<span style="color:green;font-weight:bold;">The coupon has been redeemed successfully.</span>');
							updateSummary(data.chckoutsummaryhtml);
						}
						else {
							showerror(data.response);
						}					
					});
				}
				else {
					showerror('Please enter the code.');
				}
			});
		});
		
		function showerror(error){
			jQuery('<span>').append(error)
				.addClass('inlineerror')
				.appendTo(jQuery(_obj).parent());
		}
	</script>	
<?php else:?>		
   &nbsp;
<?php endif;?>	

</div>	
<div class="grid_6" id="checkout-summary">
	<?php 
		echo App::Component('appstore')
			->helper('Checkout')
			->getChckoutSummaryHtml(
				App::Config()
					->Setting("appstoresettings_default_country_code","US")
			); 
	?>		
</div>
<div class="clear gap "></div>


<?php 
if(App::Component('appstore')->helper('Checkout')->hasShipping()):?>
	<div class="grid_8">   
		<h4 style="margin:0">
		<input name="data[Checkout][billintoshipgaddress]" id="shiptobillingaddress" onclick="jQuery('#billing_address').toggle();" type="checkbox" value="Yes" />
		<?php echo $this->__("Bill in same Shipping address");?></h4>
	</div>
	<div class="clear gap "></div>
	<div class="grid_8">   
		<h5 class="store-title"><?php echo $this->__("Shipping Address");?></h5>				
		<ul>
			<li><label><?php echo $this->__("First Name");?></label><span><input name="data[Shipping][fname]" type="text" value="" longdesc="Please enter first name" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Last Name");?></label><span><input name="data[Shipping][lname]" type="text" value="" longdesc="Please enter last name" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Address Line 1");?></label><span><input name="data[Shipping][address_line_1]" type="text" longdesc="Please enter address line 1" value="" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Address Line 2");?></label><span><input name="data[Shipping][address_line_2]" type="text" value="" class="input" /></span></li>
			<li><label><?php echo $this->__("City/Town");?></label><span><input name="data[Shipping][city]" type="text" value="" longdesc="Please enter city" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Country");?></label><span><?php echo App::Component('appstore')->helper('Checkout')->getCountryBox("data[Shipping][country]",App::Component('appStore')->Helper('Checkout')->getShippingCountry(),array("id"=>"shipping","class"=>"country-selection check_notempty","logndesc"=>"Please select country")); ?></span></li>
			<li><label><?php echo $this->__("State/Province");?></label><span id="shipping-state"><?php echo App::Component('appstore')->helper('Checkout')->getStateBox(App::Component('appStore')->Helper('Checkout')->getShippingCountry(),"data[Shipping][state]",null,array("class"=>"input	")); ?></span></li>
			<li><label><?php echo $this->__("Postal/Zip Code");?></label><span><input name="data[Shipping][zipcode] name="" type="text" value="" longdesc="Please enter postal/zip code" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Email");?></label><span><input name="data[Shipping][email]" type="text" value="" longdesc="Please enter email address" class="input check_email" /></span></li>
			<li><label><?php echo $this->__("Phone No");?></label><span><input name="data[Shipping][phoneno]" type="text" value="" class="input" /></span></li>
		</ul>
		<div class="gap clear"></div>	
	</div>	
<?php endif;?>		
	<div class="grid_8" id="billing_address">   
		<h5 class="store-title"><?php echo $this->__("Billing Address");?></h5>	
		<ul>
			<li><label><?php echo $this->__("First Name");?></label><span><input name="data[Billing][fname]" type="text" value="" longdesc="Please enter first name" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Last Name");?></label><span><input name="data[Billing][lname]" type="text" value="" longdesc="Please enter last name" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Address Line 1");?></label><span><input name="data[Billing][address_line_1]" type="text" longdesc="Please enter address line 1" value="" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Address Line 2");?></label><span><input name="data[Billing][address_line_2]" type="text" value="" class="input" /></span></li>
			<li><label><?php echo $this->__("City/Town");?></label><span><input name="data[Billing][city]" type="text" value="" longdesc="Please enter city" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Country");?></label><span><?php echo App::Component('appstore')->helper('Checkout')->getCountryBox("data[Billing][country]",App::Config()->Setting("appstoresettings_default_country_code","US"),array("id"=>"billing","class"=>"country-selection check_notempty","logndesc"=>"Please select country"),'Billing'); ?></span></li>
			<li><label><?php echo $this->__("State/Province");?></label><span id="billing-state"><?php echo App::Component('appstore')->helper('Checkout')->getStateBox(App::Config()->Setting("appstoresettings_default_country_code","US"),"data[Billing][state]"); ?></span></li>
			<li><label><?php echo $this->__("Postal/Zip Code");?></label><span><input name="data[Billing][zipcode] name="" type="text" value="" longdesc="Please enter postal/zip code" class="input check_notempty" /></span></li>
			<li><label><?php echo $this->__("Email");?></label><span><input name="data[Billing][email]" type="text" value="" longdesc="Please enter email address" class="input check_email" /></span></li>
			<li><label><?php echo $this->__("Phone No");?></label><span><input name="data[Billing][phoneno]" type="text" value="" class="input" /></span></li>
		</ul>	
		<div class="gap clear"></div>
		<div class="clear gap "></div>		
	</div>	
	<div class="grid_8">	
		<h5 class="store-title"><?php echo $this->__("Select a payment method");?></h5>	
		<div class="message paymentmessage"></div>
		<?php echo App::Component('appStore')->Helper('Pgateway_Render')->renderPaymentMethods();?>
		<div class="clear gap "></div>
		<input type="submit" value="Complete Checkout" name="data[Payment][submit]" class="button white" />
		<a href="<?php echo App::Config()->baseUrl("/store");?>" class="button orange">Back to Shopping</a>
	</div>	
</form>
<script type="text/javascript">
	jQuery(document).ready(function () {
		jQuery(".country-selection").change(function(event) {	
			var cid = jQuery(this).attr('id');		
			jQuery.getJSON(siteInfo.baseUrl + '/appstore/getstatebox/' + cid + '/' + jQuery(this).val(), function(data) {
				jQuery('#' + cid + '-state').html(data.statebox);
				if(cid =='shipping'){
					updateSummary(data.chckoutsummaryhtml);
				}
			});
		});
	});
	
	function updateSummary(chckoutsummaryhtml){
		jQuery('#checkout-summary').html(chckoutsummaryhtml);
	}
</script>
<?php  App::Helper('JavaScript')->setAjax(array("debug"=>false,"autoHide"=>false))->appForm('#post-checkout');?>
